﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccess;
using System.Data;
using System.Text;

namespace Liguo.Administration
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        String tablename = "OrderInfo A,OrderStatus B,UserInfo C";
        String condition;
        protected void Page_Load(object sender, EventArgs e)
        {
            String sendTimeLowBound=(String)Session["sendTimeLowBound"];
            String sendTimeUpBound = (String)Session["sendTimeUpBound"];
            String sendOrderTypeID = (String)Session["sendOrderTypeID"];
            String userId = (String)Session["userId"];

            SqlIt sql = new SqlIt();
            condition = "";
            if(userId!=null&&!userId.Equals(""))
            {
                condition+=" UserID="+"'"+userId+"' ";
                condition += "and";
            }
            if (sendTimeLowBound!=null&&!sendTimeLowBound.Equals(""))
            {
               condition += " datediff(SECOND,A.[Time]," + "'";
               condition += sendTimeLowBound + "')<0 ";
               condition += "and";
            }
            if (sendTimeUpBound!=null&&!sendTimeUpBound.Equals(""))
            {
                condition += " datediff(SECOND,A.[Time]," + "'";
                condition += sendTimeUpBound + "')>0 ";
                condition += "and";
            }
            if (sendOrderTypeID!=null&&!sendOrderTypeID.Equals(""))
            {
                condition += " A.Status=" + "'" + sendOrderTypeID + "' ";
                condition += "and";
            }
            condition += " B.ID=" + sendOrderTypeID;
            condition += " and C.ID=A.UserID";
            condition += " ORDER BY A.[Time] DESC";
            //要实现多表查询
            //sql语句：SELECT a.ID,A.UserID,A.[Time],A.Remark,B.Status FROM OrderInfo A,OrderStatus B WHERE a.Status='2' AND B.ID='2' and datediff(SECOND,A.[Time],'2012/1/1')<0 and  datediff(SECOND,A.[Time],'2013/11/11')>0
            
            DataSet orderset = sql.SpecialItem(tablename, condition, "A.ID,C.UserName,A.[Time],A.Remark,B.Status");
        
            GridView_OrderInfo.DataSource = orderset.Tables[0].DefaultView;
            GridView_OrderInfo.DataBind();
        }
        private void LoadPage()
        {
            SqlIt sql = new SqlIt();
            DataSet orderset = sql.SpecialItem(tablename, condition, "A.ID,C.UserName,A.[Time],A.Remark,B.Status");
            GridView_OrderInfo.DataSource = orderset.Tables[0].DefaultView;
            GridView_OrderInfo.DataBind();
        }

        //模仿star
        protected void GridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView_OrderInfo.PageIndex = e.NewPageIndex;
            //Bind data to the GridView control.
            LoadPage();
        }


        
    }



}